package com.warrant.module.rpa.finance.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

/**
 * 流水controller
 * 
 * @author cn
 * 
 */
@Path("/rest/services/bill")
public class BillController {

	/***
	 * 导入流水模板下载
	 * 
	 * @param response
	 * @return
	 */
	@GET
	@Path("/downloadTemp")
	@SuppressWarnings("resource")
	@Produces(MediaType.APPLICATION_OCTET_STREAM)
	public byte[] receiveBill(@Context HttpServletResponse response) {
		FileInputStream fis = null;
		try {
			File file = new File(getClass().getResource("到账流水导入模板.xlsx").getFile());
			System.out.println(file.getName());
			fis = new FileInputStream(file);
			byte[] b = new byte[fis.available()];
			fis.read(b);
			response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(file.getName(), "UTF-8"));
			response.setContentType("application/octet-stream");
			return b;
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return null;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}

}
